<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let str = 'hello';
            console.log(str instanceof String);
            let str1 = new String('world');
            console.log(str1 instanceof String);

            function Person(name, age) {
                this.name = name;
                this.age = age;
            }
            let person1 = new Person('zs', 19);
            console.log(person1 instanceof Person);
            console.log(person1 instanceof Object);

            function myInstanceOf(left, right) {
                // 获取对象的的原型
                let proto = Object.getPrototypeOf(left);
                // 获取构造函数的 prototype 原型对象
                let prototype = right.prototype;
                while (true) {
                    // 说明到达了原型链的终点，说明该构造函数不在该原型对象上
                    if (!proto) return false;
                    if (proto === prototype) return true;
                    // 一直沿着原型链向上查找
                    proto = Object.getPrototypeOf(proto);
                }
            }
        </script>
    </body>
</html>
